package edu.sctu.lab03;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created by dell on 2018/5/28.
 */
public class UserListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        resp.setHeader("content-type", "text/html;charset=UTF-8");

        PrintWriter out = resp.getWriter();

        //out.write("<table>");
      //  out.write("<tr>");
        //out.write("<td>编号</td>");
       // out.write("<td>用户名</td>");
      //  out.write("<td>密码</td>");
      //  out.write("<td>操作1</td>");
       // out.write("<td>操作2</td>");
       // out.write("</tr>");
       // out.write("<tr>");
     //   out.write("<td>1001</td>");
       // out.write("<td>chen</td>");
      //  out.write("<td>123</td>");
      //  out.write("<td>删除</td>");
       // out.write("<td>更新</td>");
       // out.write("</tr>");
       // out.write("</table>

        // 1. 查数据库并且得到userList
        Database database = new Database();
        List<User> userList = database.getUserList();

        // 2. request空间中新建一个名为userList的变量
        req.setAttribute("userList", userList);


        // 3. 跳转到userList.jsp页面
        req.getRequestDispatcher("/userList.jsp")
                .forward(req, resp);

    }
}








